<?php

namespace App\Models\Wechat;

use Illuminate\Database\Eloquent\Model;

class ClientUserModel extends Model
{
    //
    protected $table = 'client_users';


    static function Subscribe($openid)
    {
        ClientUserLogModel::query()->insert(['user_id' => $openid, 'status' => 1]);
        if (static::query()->where('id', $openid)->count() > 0) {
            return static::query()->where('id', $openid)->update(['is_subscribed'=> 1]);
        }
        return static::query()->insert(['id' => $openid]);
    }

    static function UnSubscribe($openid)
    {
        ClientUserLogModel::query()->insert(['user_id' => $openid, 'status' => 0]);
        return static::query()->where('id', $openid)->update(['is_subscribed'=> 0]);
    }
}
